From 9f2f713fcd950a559e318b90dfc6ab11b7014aea Mon Sep 17 00:00:00 2001 From: oliskoli Date: Thu, 21 Aug 2008 22:01:43 +0000 Subject: [PATCH] defs/util: Add functions to assign (compiler friendly) an int to a pointer and back. --- gpsbabel/defs.h | 3 +++ gpsbabel/util.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 4f774cd8b..891d4cd9e 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -951,6 +951,9 @@ typedef enum { char gb_getbit(const void *buf, const gbuint32 nr); void gb_setbit(void *buf, const gbuint32 nr); +void *gb_int2ptr(const int i); +int gb_ptr2int(const void *p); + /* * From parse.c */ diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 175f42750..4fdd2bb7c 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -1760,3 +1760,30 @@ char gb_getbit(const void *buf, const gbuint32 nr) return (bytes[nr / 8] & (1 << (nr % 8))); } + +/* + * gb_int2ptr: Needed, when sizeof(*void) != sizeof(int) ! compiler warning ! + */ +void *gb_int2ptr(const int i) +{ + union { + void *p; + int i; + } x = { NULL }; + + x.i = i; + return x.p; +} + +/* + * gb_ptr2int: Needed, when sizeof(*void) != sizeof(int) ! compiler warning ! + */ +int gb_ptr2int(const void *p) +{ + union { + const void *p; + int i; + } x = { p }; + + return x.i; +} -- 2.30.2